<template>
  <el-form-item label="接口管理" style="width: 100%">
    <el-button type="primary" icon="plus" @click="handleAdd" style="margin-bottom: 15px"> 添加 </el-button>
    <el-table :data="modelValue" border height="262" style="width: 100%">
      <!-- <el-table-column label="资源名称" width="200px">
        <template #default="{ row, $index }">
          <el-input v-model="modelValue[$index].name" placeholder="请输入名称"></el-input>
        </template>
      </el-table-column> -->
      <el-table-column label="接口类型" width="140px">
        <template #default="{ row, $index }">
          <el-select v-model="modelValue[$index].method" placeholder="请输入地址">
            <el-option
              v-for="(item, index) in [
                { label: 'ALL', value: '*' },
                { label: 'GET', value: 'GET' },
                { label: 'POST', value: 'POST' },
                { label: 'PUT', value: 'PUT' },
                { label: 'DELETE', value: 'DELETE' },
              ]"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option
          ></el-select>
        </template>
      </el-table-column>
      <el-table-column label="接口路径">
        <template #default="{ row, $index }">
          <el-input v-model="modelValue[$index].path" placeholder="请输入路径"></el-input>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="80px">
        <template #default="scope">
          <el-button link type="primary" icon="delete" @click="modelValue.splice(scope.$index, 1)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-form-item>
</template>
<script setup>
const props = defineProps({
  modelValue: { type: Array, default: () => [] },
})

const apiList = ref([])
const key = ref('')
const keyword = ref('')
const emit = defineEmits(['change'])

const onOpen = () => {}

// 新增
function handleAdd() {
  props.modelValue.push({
    method: '*',
    path: '',
  })
}

defineExpose({
  onOpen,
})
</script>
<style lang="scss" scoped></style>
